﻿using SF.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SF.Ucenter.admin.statistics
{
    public partial class sourceapp : System.Web.UI.Page
    {
        protected string customer_source = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[DTKeys.SESSION_APP_INFO] != null)
            {
                string appNum = Session[DTKeys.SESSION_APP_INFO].ToString(); 
                customer_source = GetCustomerSourceByAppNum(appNum);
            }
            else
            {
                customer_source = GetCustomerSourceByAppNum("");
            }
        }


        protected string GetCustomerSourceByAppNum(string appNum)
        {
            BLL.statistics bll = new BLL.statistics();
            System.Data.DataSet dsSource = bll.GetCustomerSourceByAppNum();
            if (appNum!="")
            {
                dsSource = bll.GetCustomerSourceByAppNum(appNum);
            }
            string strCities = string.Empty;
            foreach (System.Data.DataRow r in dsSource.Tables[0].Rows) 
            {
                if (strCities.IndexOf(r["city"].ToString()) == -1) 
                {
                    strCities += r["city"] + ",";
                }
            }

            string arr_series = string.Empty;
            if (strCities.Length > 0)
            {
                string [] cities = strCities.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);                

                for (int i = 0; i < cities.Length; i++)
                {
                    System.Data.DataRow [] rows = dsSource.Tables[0].Select("city='"+cities[i]+"'");
                    if (i == 0)
                    {
                        arr_series += "{name: '"+cities[i]+"',y: "+rows[0]["count"]+",sliced: true,selected: true}, "; ;
                    }
                    else 
                    {
                        arr_series += "{name: '" + cities[i] + "',y: " + rows[0]["count"] + "}, ";
                    }
                }
            }

            return arr_series; 
        }
    }
}